/*
 * @Author: wuzhouhai wzh200x@126.com
 * @Date: 2024-08-01 17:37:29
 * @LastEditors: wuzhouhai wzh200x@126.com
 * @LastEditTime: 2024-08-07 15:45:25
 * @FilePath: \dwys_web\assets\script\ui\shopPmt\ShopPmt.ts
 * @Description: 
 */
import { _decorator, Component, Node } from 'cc';
import { CCComp } from '../../../../extensions/oops-plugin-framework/assets/module/common/CCComp';
import { Label } from 'cc';
import * as proto from "../../phoenix/protoc/ts/proto_app.js";
import { oops } from '../../../../extensions/oops-plugin-framework/assets/core/Oops';
import { GameEvent } from '../../common/event/GameEvent';
const { ccclass, property } = _decorator;

@ccclass('ShopPmt')
export class ShopPmt extends CCComp {

    @property(Label)
    pmtName:Label | undefined = undefined;

    @property(Label)
    pmtLevel:Label | undefined = undefined;

    @property(Label)
    cyLevel:Label | undefined = undefined;

    private pmt:proto.Iroom_pmt_info | undefined = undefined;
    reset(): void {
        throw new Error('Method not implemented.');
    }
    
    start() {
        oops.message.on(GameEvent.UpdateRoomPmt, this.onUpdatePmtInfo, this);
    }

    protected onDestroy(): void {
        oops.message.off(GameEvent.UpdateRoomPmt, this.onUpdatePmtInfo, this);
    }

    update(deltaTime: number) {
        
    }

    InitPmt(pmt:proto.Iroom_pmt_info){
        this.pmt = pmt;
        this.pmtName!.string = this.pmt.name!;
        this.SetPmtLevel(this.pmt.pmtLevel!);
        this.SetCyLevel(this.pmt.level!);
    }

    SetPmtLevel(level:number){
        this.pmtLevel!.string ="lv." + level.toString();
    }

    SetCyLevel(level:number){
        this.cyLevel!.string ="cy." + level.toString();
    }

    onClickSelectPmt(){
        console.log("onClickSelectPmt", this.pmt);
        oops.message.dispatchEvent(GameEvent.SelectPmt, this.pmt);
    }

    onUpdatePmtInfo(event:string, pmt:proto.Iroom_pmt_info){
        if(pmt && this.pmt!.id == pmt!.id){
            this.pmt!.level = pmt.level;
            this.pmt!.pmtLevel = pmt.pmtLevel;
            this.SetPmtLevel(this.pmt!.pmtLevel!);
            this.SetCyLevel(this.pmt!.level!);
        }
    }
}


